<?php 
	require_once 'dbHandler.php';
// ----------------------------------------------------------------
// Employee class
// ----------------------------------------------------------------	

	class Employee
	{
		private $name = 'N/A';
		private $salary = 'N/A';
		private $password = 'N/A';
		private $eid = 'N/A';
		
		public function __construct()
		{
			$this->name = 'N/A';
			$this->salary = 'N/A';
			$this->password = 'N/A';
		}

		public function getEmployee($user, $pass)
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM employee WHERE name = '$user' AND password = '$pass'"; 
			$result = $DTB->query($query);
			$employee = new Employee();
			//return $result;
			while($row = mysql_fetch_array($result))
			{
				$employee->name = mysql_result($result,0,'name');
				$employee->salary = mysql_result($result,0,'address');
				$employee->password = mysql_result($result,0,'password');
				$employee->eid = mysql_result($result,0,'eid');
			}
		
			if($employee->name == $user && $employee->password == $pass)
			{
				return $employee;
			}
			else 
			{
				return $employee;
			}
		}
	
		public function getSalary()
		{
			return $this->salary;	
		}
	
		public function getPassword()
		{
			return $this->password;
		}
	
		public function getName()
		{
			return $this->name;
		}

		public function getEid()
		{
			return $this->eid;
		}
		
		public function getEmpJobs($id)
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM workson WHERE eid = '$id'";
			$result = $DTB->query($query);
			return $result;
		}
		public function completeOrder($ordernumber)
		{
			$DTB = dbHandler::getInstance();
			$query = "DELETE FROM workson WHERE order_no = '$ordernumber'";
			$result = $DTB->query($query);
			$query = "UPDATE orders SET is_Complete = 'YES'WHERE order_no ='$ordernumber'";
			$result = $DTB->query($query);
		}
		public function viewOrder($order)
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT item_no FROM orderitem WHERE order_no = '$order'";
			$result = $DTB->query($query);
			$itemNo = array();
			while($row = mysql_fetch_array($result))
			{
				array_push($itemNo,$row['item_no']);
			}
			$arraylength = count($itemNo);
			$current = 0;
			while($current < $arraylength)
			{
				//echo $itemNo[0];
				echo $this->getItemName($itemNo[$current])." X". $this->getItemQuant($itemNo[$current],$order);
				echo "<br>";
				$current++;
			}
		}
		public function getItemName($itemid)
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT name FROM item WHERE no = '$itemid'";
			$result = $DTB->query($query);
			$name = mysql_result($result,0,'name');
			return $name;
		}
		public function getItemQuant($itemid,$order)
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT quantity FROM orderitem WHERE item_no = '$itemid' AND order_no = '$order'";
			$result = $DTB->query($query);
			$quant = mysql_result($result,0,'quantity');
			return $quant;
		}
	}
?>